package insat.challenge;

import insat.challenge.metier.DBAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AjouterContactActivity extends DashboardActivity implements OnClickListener{

	Button bt;
	DBAdapter db;
	EditText editText1;
	EditText editText2;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ajouter_contact);
		
		bt = (Button)findViewById(R.id.button_ajoutercontact);
		editText1 = (EditText)findViewById(R.id.editText_newnomprenom);
		editText2 = (EditText)findViewById(R.id.editText_newnumtel);
		bt.setOnClickListener(this);
		db = new DBAdapter(this);
		
		
	}
	
	

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		if(editText1.getText().toString().equals("") || editText2.getText().toString().equals("") || 
				editText1.getText() ==null || editText2.getText()==null)
		{
			Toast toast;// =new Toast(this.getApplicationContext());
			Toast.makeText(this.getApplicationContext(), "Vérifiez vos champs", Toast.LENGTH_SHORT).show();
			//toast.show();
		}
		
		else
		{	Editable nompenom =editText1.getText();
		Editable numTel = editText2.getText();
		String nompr = nompenom.toString();
		String numtel = numTel.toString();
		
		
			db.open();
			db.insererUnContact(nompr, numtel);
			db.close();
			startActivity(new Intent(AjouterContactActivity.this,ContacterActivity.class));
			
			
		}
	}
}
